%% Fig.5(a)
clc; clear; close all;

%% 参数
g11   = 1.4;  g12 = -2;
g21   = 1.4;  g22 = 1.6;
k     = 2.2;
x0    = [0.01; 0; 0];
dt    = 0.01;
t_ends= [1000, 4000, 10000];
styles= {'k--','b-.','r-'};
labels= {'\tau_{end}=1000','\tau_{end}=4000','\tau_{end}=10000'};

%% 并行积分
traj = cell(3,1);
parfor j = 1:3
    T = t_ends(j);
    N = round(T/dt);
    X = zeros(3,N+1);  X(:,1)=x0;
    for i=1:N
        X(:,i+1)=RK4(@(x)MBNHNN(x,k,g11,g12,g21,g22),X(:,i),dt);
    end
    traj{j}=X;
end

%% 分三步画：红→蓝→黑
figure; hold on;
hR = plot(traj{3}(3,:), traj{3}(1,:), styles{3}, 'LineWidth',1.2);
hB = plot(traj{2}(3,:), traj{2}(1,:), styles{2}, 'LineWidth',1.2);
hK = plot(traj{1}(3,:), traj{1}(1,:), styles{1}, 'LineWidth',1.2);

xlabel('x_3','FontSize',12);
ylabel('x_1','FontSize',12);
title(sprintf('Fig.5(a): k = %.1f', k), 'FontSize',14);
legend([hK,hB,hR], labels, 'Location','northeast','FontSize',10);
grid on;
